package com.cs.study.homework._0206;

import java.awt.*;
import java.util.Arrays;
import java.util.Scanner;

public class Add {
    public static void main(String[] args) {
        System.out.println("请输入要输入的人名：");
        Scanner sc = new Scanner(System.in);
        String name = sc.nextLine();
        String[] arr = new String[]{"张三","李四","王五"};
        //输出数组内容
        printArray(arr);
        //定义新数组
        String[] newArray = new String[arr.length + 1];
        getNewArray(arr,newArray,name);
        System.out.println(Arrays.toString(newArray));

    }



    public static void printArray(String[] arr) {
        for(int i=0; i<arr.length; i++) {
            System.out.print(arr[i] + ", ");
        }
        System.out.println();
    }

    public static void getNewArray(String[] oddArray,String[] newArray, String name) {
        for (int i = 0; i < oddArray.length; i++) {
             if (!oddArray[i].equals(name)) {
                newArray[i] = oddArray[i];
                newArray[i + 1] = name;
            }
        }
    }
}

